from django.db import models
from utils.models import CoreModel,BaseModel
from apps.address.models import Address
from mysystem.models import Users
# Create your models here.


# ================================================= #
# ************** 路线 model  ************** #
# ================================================= #
class Goods(CoreModel):
    name = models.CharField(max_length=60, verbose_name='标题',null=True, blank=True)
    nums = models.PositiveSmallIntegerField(default=0, null=True, help_text='显示顺序', verbose_name='排序')
    times = models.JSONField(max_length=20, verbose_name='站点',null=True, blank=True)
    stations = models.JSONField(max_length=20, verbose_name='站点',null=True, blank=True)
    prices = models.JSONField(max_length=20, verbose_name='站点',null=True, blank=True)
    status = models.BooleanField(default=True, verbose_name="商品类别状态", help_text="商品类别状态")
    is_delete = models.BooleanField(default=False, verbose_name="是否逻辑删除", help_text="是否逻辑删除")
    class Meta:
        ordering = ["create_datetime"]
        db_table = 'tb_goods'
        verbose_name = '商品SKU'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.stations

# ================================================= #
# ************** 商品订单model  ************** #
# ================================================= #
class OrderInfo(CoreModel):
    """订单信息"""
    PAY_METHOD_CHOICES = (
        (0, ""),
        (1, "货到付款"),
        (2, "微信"),
        (3, "支付宝"),

    )
    ORDER_STATUS_CHOICES = (
        (1, "待支付"),
        (2, "待发货"),
        (3, "待收货"),
        (4, "待评价"),
        (5, "已完成"),
        (6, "已取消"),
    )
    ORDER_PAY_STATUS_CHOICES = (
        (0, "待支付"),
        (1, "已支付"),
        (2, "退款中"),
        (3, "退款失败"),
        (4, "已退款"),
    )

    order_id = models.CharField(max_length=64, verbose_name="订单号",unique=True)#内部
    trade_id = models.CharField(max_length=100, unique=True, null=True, blank=True, verbose_name="支付编号")#外部
    user = models.ForeignKey(Users, on_delete=models.PROTECT,related_name='createorderuser1' ,verbose_name="下单用户")
    goods_id = models.CharField(max_length=100, verbose_name="物流单号",null=True, blank=True)#该商城项目特有，其他项目可去掉
    start = models.CharField(max_length=50, null=True, blank=True, verbose_name="收货人姓名")
    end = models.CharField(max_length=100, null=True, blank=True, verbose_name="收货详细地址")
    times = models.CharField(max_length=100, null=True, blank=True, verbose_name="收货详细地址")
    mobile = models.CharField(max_length=20, null=True, blank=True, verbose_name="收货人手机号")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="实付商品总金额",default=0)
    count = models.IntegerField(default=1, verbose_name="商品总数")
    total_pay = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="订单总金额",default=0)
    pay_method = models.SmallIntegerField(choices=PAY_METHOD_CHOICES, default=0, verbose_name="支付方式")
    pay_time = models.CharField(max_length=64,null=True, blank=True, verbose_name="支付时间", help_text="支付时间")
    remark = models.CharField(max_length=100, verbose_name="订单备注",null=True,blank=True)
    cancel_reason = models.CharField(max_length=100, verbose_name="订单取消原因", null=True, blank=True)
    status = models.SmallIntegerField(choices=ORDER_STATUS_CHOICES, default=1, verbose_name="订单状态")
    pay_status = models.SmallIntegerField(choices=ORDER_PAY_STATUS_CHOICES, default=0, verbose_name="支付状态")
    is_delete = models.BooleanField(default=False, verbose_name="是否逻辑删除", help_text="是否逻辑删除")

    class Meta:
        db_table = "tb_mall_order_info"
        verbose_name = '订单基本信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.order_id
